/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Madason.MetaModel.Validation;

namespace Madason.MetaModel
{
	public class StateTransition : ModelElement
	{
		public const string WARNING_TRANSITION_NO_EVENT = "The Transition has no event and so can't be used";
		private State source;
		private State target;
		private string guard;
		private StateTransitionTriggerList trigger = new StateTransitionTriggerList();
		private StateActionList actions = new StateActionList();

		/// <summary>
		/// Transition Source
		/// </summary>
		public State Source
		{
			get { return source; }
			set { source = value; }
		}

		
		/// <summary>
		/// Transition Target
		/// </summary>
		public State Target
		{
			get { return target; }
			set { target = value; }
		}

		
		/// <summary>
		/// Guard condition
		/// </summary>
		public string Guard
		{
			get { return guard; }
			set { guard = value; }
		}
	
		
		/// <summary>
		/// Trigger
		/// </summary>
		public StateTransitionTriggerList Trigger
		{
			get { return trigger; }
			set { trigger = value; }
		}

		

		public StateActionList Actions
		{
			get { return actions; }
			set { actions = value; }
		}


		public override void Validate(Madason.MetaModel.Validation.ValidationIssueList issues)
		{
			if (trigger.Count == 0 && source.StateType != StateType.Initial &&
				source.StateType != StateType.Branch)
				issues.Add(new ValidationIssue(WARNING_TRANSITION_NO_EVENT, ValidationIssueSeverity.Warning, this));
		}
	}

	public class StateTransitionList : ArrayList
	{
		public StateTransition this[int i]
		{
			get
			{
				return base[i] as StateTransition;
			}
		}
	}
}
